package com.base.controller;

import com.base.entity.bo.ExpertBo;
import com.base.entity.bo.ExpertGroupBO;
import com.base.entity.bo.SciencePersonBo;
import com.base.entity.vo.ExpertGroupVo;
import com.base.entity.vo.ExpertVo;
import com.base.entity.vo.SciencePersonVo;
import com.base.service.ExpertGroupService;
import com.base.service.ExpertService;
import com.base.service.SciencePersonService;
import com.base.utils.CutPageBean;
import com.base.utils.Result;
import com.common.utils.poi.ExcelUtil;
import com.common.utils.uuid.IdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Api(tags = "专家人才")
@RestController
@RequestMapping("/zjrc")
public class ExpertController {
    @Autowired
    ExpertService expertService;

    @PostMapping("/getExpertList")
    @ApiOperation(value = "查询专家分组成员")
    public Result getExpertList(@RequestBody ExpertVo expertVo){
        List<ExpertBo> list =expertService.getExpertList(expertVo);
        return Result.succ(list);
    }

    @PostMapping("/getExpertHaveList")
    @ApiOperation(value = "查询专家分组已有成员")
    public Result getExpertHaveList(@RequestBody ExpertVo expertVo){
        if(expertVo.getGroupId() != null && expertVo.getGroupId() != ""){
            List<ExpertBo> list =expertService.getExpertHaveList(expertVo);
            return Result.succ(list);
        }else {
            String[] emptyStringArray = new String[0];
            return Result.succ(emptyStringArray);
        }
    }

    @PostMapping("/selectExpertList")
    @ApiOperation(value = "查询专家人才列表")
    public Result selectExpertList(@RequestBody ExpertVo expertVo){
        CutPageBean<ExpertBo> cutPageBean =expertService.selectExpertList(expertVo);
        return Result.succ(cutPageBean);
    }

    @PostMapping("/deletExpert")
    @ApiOperation(value = "删除专家人才")
    public Result deletExpert(@RequestBody ExpertBo expertBo){
        int row=expertService.deletExpert(expertBo);
        if (row == 1) {
            return Result.succ("删除成功");
        } else if(row ==0){
            return Result.fail("删除失败");
        }else {
            return Result.fail("评审专家中存在该专家，不能删除");
        }
    }

    @PostMapping("/insertExpertList")
    @ApiOperation(value = "新增校外专家")
    public Result insertExpertList(@RequestBody ExpertBo expertBo){
        int row=expertService.insertExpertList(expertBo);
        if (row > 0) {
            return Result.succ("新增成功");
        } else {
            return Result.fail("新增失败");
        }
    }

    @PostMapping("/updateExpertList")
    @ApiOperation(value = "编辑专家人才")
    public Result updateExpertList(@RequestBody ExpertBo expertBo){
        int row=expertService.updateExpertList(expertBo);
        if (row > 0) {
            return Result.succ("更新成功");
        } else {
            return Result.fail("更新失败");
        }
    }

    @PostMapping("/selectExpertDetails")
    @ApiOperation(value = "查询专家人才详情")
    public Result selectExpertDetails(@RequestBody ExpertVo expertVo){
        List<ExpertBo> list =expertService.selectExpertDetails(expertVo);
        return Result.succ(list);
    }

    @PostMapping("/getPersonHaveList")
    @ApiOperation(value = "查询校内专家")
    public Result getPersonHaveList(@RequestBody SciencePersonVo sciencePersonVo){
        List<SciencePersonBo> list =expertService.getPersonHaveList(sciencePersonVo);
        return Result.succ(list);
    }

    @PostMapping("/insertSchoolExpertList")
    @ApiOperation(value = "新增校内专家")
    public Result insertSchoolExpertList(@RequestBody ExpertVo expertVo){
        int row=expertService.insertSchoolExpertList(expertVo);
        if (row > 0) {
            return Result.succ("新增成功");
        } else {
            return Result.fail("新增失败");
        }
    }

    @ApiOperation("导出专家人才列表")
    @PostMapping("/exportList")
    public void exportList(HttpServletResponse response, @RequestBody ExpertVo expertVo) {
        List<ExpertBo> list =expertService.exportList(expertVo);
        ExcelUtil<ExpertBo> util = new ExcelUtil<>(ExpertBo.class);
        util.exportExcel(response, list, "专家人才列表","专家人才列表");
    }
}